<?php

namespace Cframe;

class Config{
    private static $config = array();

    private static function load(){
        if (empty(static::$config)){
            static::$config = include CONFIG_PATH."Config.php";
            $config = include CON_PATH . 'Config.php';
            if (is_array($config) && !empty($config)){
                static::$config = array_merge(static::$config,$config);
            }
        }
    }

    /**
     * @param $name 获取的配置名称
     * @return mixed 返回其配置的内容
     * @throws \ErrorException 如果不存在则抛出异常
     */
    private static function get($name){
        if (!isset(static::$config[$name])){
            return false;
        }
        return static::$config[$name];
    }

    public static function configs($func = '',$name = ''){
        static::load();
        switch (strtolower($func)){
            case "get":
                $value = static::get($name);
                break;
        }
        if (isset($value)){
            return $value;
        }
    }

    public static function __callStatic($name, $arguments){
        array_unshift($arguments,$name);
        return call_user_func_array([__CLASS__,"configs"],$arguments);
    }
}